package cn.edu.nuc.android.oweibo.tasks;

import weibo4android.Weibo;
import weibo4android.WeiboException;
import android.os.AsyncTask;

public class PostWeiboAsyncTask extends AsyncTask<String, Void, weibo4android.Status> {

	private PostWeiboResponder responder;
	private Weibo weibo;
	
	public PostWeiboAsyncTask(PostWeiboResponder responder, Weibo weibo) {
		super();
		this.responder = responder;
		this.weibo = weibo;
	}

	public interface PostWeiboResponder {
		public void weiboPosting();
		public void weiboPosted(weibo4android.Status status);
	}

	@Override
	protected weibo4android.Status doInBackground(String... params) {
		String content = params[0];
		try {
			return weibo.updateStatus(content);
		} catch (WeiboException e) {
			throw new RuntimeException("Couldn't post status", e);
		}
	}
	
	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		responder.weiboPosting();
	}

	@Override
	protected void onPostExecute(weibo4android.Status result) {
		super.onPostExecute(result);
		responder.weiboPosted(result);
	}

}
